<?php

class Tourism_goods_exotic_model extends CI_Model
{
    private $table = 'tourism_goods_exotic';
    
    public function findById($id)
    {
        $this->db->where('id',$id);
        return $this->db->get($this->table);
    }
    
    public function total($param = array())
    {
        if (!empty($param['name'])) {
            $this->db->like('name', $param['name']);
            $this->db->or_like('abstract', $param['name']);
        }
        return $this->db->count_all_results($this->table);
    }

    public function page_list($page_num, $num, $param = array())
    {
        if (!empty($param['name'])) {
            $this->db->like('name', $param['name']);
            $this->db->or_like('abstract', $param['name']);
        }
        $this->db->limit($page_num, $num);
        return $this->db->get($this->table);
    }

    public function insertTourismGoodsExotic($postData)
    {
        $data = array(
            'name'      => $postData['name'],
            'region_id' => $postData['region_id'],
            'abstract'  => $postData['abstract'],
            'describe'  => $postData['describe'],
            'advert'    => $postData['advert'],
            'sort'      => !empty($postData['sort']) ? $postData['sort'] : 100,
        );
        if (!empty($postData['picture'])) {
            $data['picture'] = $postData['picture'];
        }
        if (!empty($postData['images'])) {
            $data['images'] = $postData['images'];
        }
        $this->db->insert($this->table, $data);
        return $this->db->insert_id();
    }
    
    public function updateTourismGoodsExotic($postData)
    {
        $data = array(
            'name'      => $postData['name'],
            'region_id' => $postData['region_id'],
            'abstract'  => $postData['abstract'],
            'describe'  => $postData['describe'],
            'advert'    => $postData['advert'],
            'sort'      => !empty($postData['sort']) ? $postData['sort'] : 100,
        );
        if (!empty($postData['picture'])) {
            $data['picture'] = $postData['picture'];
        }
        if (!empty($postData['images'])) {
            $data['images'] = $postData['images'];
        }
        $this->db->where('id', $postData['id']);
        return $this->db->update($this->table, $data);
    }

}